if (!jsx3.lang.Class.forName("ux.cdb.admin.system.department.Department")) {
    /**
     * Define the <code>name of class</code> class.
     * This class inherit from <code>jsx3.gui.Block<code> GUI class.
     */
    jsx3.Class.defineClass(
            "ux.cdb.admin.system.department.Department",
            ux.megatron.gui.Block,
            null,
            function (objRoot) {
                /**
                 * This method will be called after UI file has deserialized.
                 */
                objRoot.prototype.onAfterDeserialize = function() {
                    this.typeDoc = jsx3.xml.CDF.Document.newDocument().loadXML(ux.megatron.Main.loadResource("ux/cdb/admin/system/department/docs/Type.xml", "ux.cdb.admin", "DepartmentTypeDoc", "xml"));
                    this.levelDoc = jsx3.xml.CDF.Document.newDocument().loadXML(ux.megatron.Main.loadResource("ux/cdb/admin/system/department/docs/Level.xml", "ux.cdb.admin", "DepartmentLevelDoc", "xml"));
                    this.statusDoc = jsx3.xml.CDF.Document.newDocument().loadXML(ux.megatron.Main.loadResource("ux/cdb/admin/system/department/docs/Status.xml", "ux.cdb.admin", "DepartmentStatusDoc", "xml"));
                    this.modeDoc = jsx3.xml.CDF.Document.newDocument().loadXML(ux.megatron.Main.loadResource("ux/cdb/admin/system/department/docs/Mode.xml", "ux.cdb.admin", "DepartmentModeDoc", "xml"));
                    this.hideDetails();
                    this.disableEdit();
                    this.disableDelete();
                    this.selectedId = null;
                };
                objRoot.prototype.getSelectedId = function(){
                    return this.selectedId;
                };
                objRoot.prototype.getMatrix = function(){
                    //alert(this.getDescendantOfName("mtxMain"));
                    return this.getDescendantOfName("mtxTree");
                };
                objRoot.prototype.onDepartmentSelected = function(objMtx, objEVENT, strRECORDID){
                    if(strRECORDID){
                        this.selectedId = strRECORDID;
                        this.showDetails();
                        this.enableEdit();
                        this.enableDelete();
                        var departmentRecordNode = objMtx.getRecord(strRECORDID);
                        departmentRecordNode["Org_Type_Code"] = this.typeDoc.getRecord(departmentRecordNode["Org_Type_Code"]) ? this.typeDoc.getRecord(departmentRecordNode["Org_Type_Code"])["jsxtext"] : "";
                        departmentRecordNode["Org_Level_Code"] = this.levelDoc.getRecord(departmentRecordNode["Org_Level_Code"]) ? this.levelDoc.getRecord(departmentRecordNode["Org_Level_Code"])["jsxtext"] : "";
                        departmentRecordNode["Internal_Org_Status_Code"] = this.statusDoc.getRecord(departmentRecordNode["Internal_Org_Status_Code"]) ? this.statusDoc.getRecord(departmentRecordNode["Internal_Org_Status_Code"])["jsxtext"] : "";
                        departmentRecordNode["Branch_Approve_Mode_Code"] = this.modeDoc.getRecord(departmentRecordNode["Branch_Approve_Mode_Code"]) ? this.modeDoc.getRecord(departmentRecordNode["Branch_Approve_Mode_Code"])["jsxtext"] : "";
                        var cdfDoc = jsx3.xml.CDF.Document.newDocument();
                        cdfDoc.insertRecord(departmentRecordNode);
                        this.getDescendantOfName("blk_departmentDetails").setData(cdfDoc);
                    } else {
                        this.selectedId = null;
                        this.hideDetails();
                        this.disableEdit();
                        this.disableDelete();
                    }
                };
                objRoot.prototype.onNewClicked = function(objBtn, objEVENT){
                    this._doAddDepartment()
                };
                objRoot.prototype._doAddDepartment = function(){
                    ux.megatron.Main.loadUIResourceAsync(this, "ux.cdb.admin", "ux/cdb/admin/system/department/departmentWizard/ui/DepartmentBuilderDailog.xml");
                };
                objRoot.prototype.onModifyClicked = function(objBtn, objEVENT){
                    var me = this;
                    ux.megatron.Main.loadUIResourceAsync(this, "ux.cdb.admin", "ux/cdb/admin/system/department/departmentWizard/ui/DepartmentBuilderDailog.xml", me, me.onWizardLoaded);
                    jsx3.log("Edit clicked.");
                };
                objRoot.prototype.onWizardLoaded = function(){
                    if(this.selectedId){
                        var wizPane = this.getDescendantOfName("wizPane_1");
                        var selectedRecord = this.getMatrix().getRecord(this.selectedId);
                        if(selectedRecord){
                            wizPane.setData(selectedRecord);
                        } else {
                            alert("error");
                        }
                    }
                };
                objRoot.prototype.onRemoveClicked = function(objBtn, objEVENT){
                    jsx3.log("Remove clicked.");
                    if(this.selectedId){
                        var mtx = this.getMatrix();
                        mtx.deleteRecord(this.selectedId, true);
                        this.selectedId = null;
                        this.hideDetails();
                    }
                };
                objRoot.prototype.showDetails = function(){
                    this.getDescendantOfName("blk_departmentNoSelected").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                    this.getDescendantOfName("blk_departmentDetails").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                };
                objRoot.prototype.hideDetails = function(){
                    this.getDescendantOfName("blk_departmentNoSelected").setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                    this.getDescendantOfName("blk_departmentDetails").setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                };
                objRoot.prototype.enableEdit = function(){
                    this.getDescendantOfName("btn_editDepartment").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                };
                objRoot.prototype.disableEdit = function(){
                    this.getDescendantOfName("btn_editDepartment").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                };
                objRoot.prototype.enableDelete = function(){
                    this.getDescendantOfName("btn_deleteDepartment").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                };
                objRoot.prototype.disableDelete = function(){
                    this.getDescendantOfName("btn_deleteDepartment").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                };
            }
    );
}